﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace MVCWeb.Models
{
  public class PLStudent
  {
    [Required]
    [DisplayName("Student ID")]
    public string ID { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [DisplayName("Social Security #")]
    public string SSN { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [DisplayName("First Name")]
    public string FirstName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [DisplayName("Last Name")]
    public string LastName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [DisplayName("Email")]
    public string EmailAddress { get; set; }

  }

  public static class StudentClientService
  {
    public static List<PLStudent> GetStudentList()
    {
      List<PLStudent> studentList = new List<PLStudent>();

      MVCWeb.SLStudent.ISLStudent SLStudent = new MVCWeb.SLStudent.SLStudentClient();

      string[] errors = new string[0];
      MVCWeb.SLStudent.Student[] studentsFromBL = SLStudent.GetStudentList(ref errors);

      foreach (MVCWeb.SLStudent.Student s in studentsFromBL)
      {
        PLStudent student = new PLStudent();
        student.ID = s.id;
        student.SSN = s.ssn;
        student.FirstName = s.first_name;
        student.LastName = s.last_name;
        student.EmailAddress = s.email;

        studentList.Add(student);
      }

      return studentList;
    }

    public static void CreateStudent(PLStudent s)
    {
      MVCWeb.SLStudent.Student newStudent = new SLStudent.Student();

      newStudent.id = s.ID;
      newStudent.ssn = s.SSN;
      newStudent.first_name = s.FirstName;
      newStudent.last_name = s.LastName;
      newStudent.email = s.EmailAddress;

      MVCWeb.SLStudent.ISLStudent SLStudent = new MVCWeb.SLStudent.SLStudentClient();
      string[] errors = new string[0];
      SLStudent.InsertStudent(newStudent, ref errors);
    }
  }


}